<!DOCTYPE html>
<html lang="en">
<head>
<title>LanZouCloud解析</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="images/favicon.ico">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<!-- Material Design Icons CSS -->
<link rel="stylesheet" href="css/materialdesignicons.css">
<!-- Bootstrap Checkbox CSS -->
<link rel="stylesheet" href="css/awesome-bootstrap-checkbox.css">
<!-- Rippler CSS -->
<link rel="stylesheet" href="css/rippler.min.css">
<!-- Style CSS -->
<link rel="stylesheet" href="css/style.css">
<!-- Responsive  CSS -->
<link rel="stylesheet" href="css/responsive.css">
</head>
<body>
<script> 
    var downloadLink = '';
    function jiexi2(id){
        var link = document.getElementById("link").value
        var xhr = new XMLHttpRequest();
		xhr.onreadystatechange = function(){
		if (xhr.readyState === 4){
			if (xhr.status === 200){
				document.getElementById("link").value = link.substring(0,link.length-xhr.responseText.length) + id
				document.getElementById("password").value = ''
				jiexi()
			} else {
			console.error(xhr.statusText);
			}
		}
		};
		xhr.onerror = function (e) {
		console.error(xhr.statusText);
		};
		xhr.open('GET', './id.php?link=' + link, true);
		xhr.send(null);
        
        
    }
	function jiexi(){ 
		var link = document.getElementById("link").value
		var password = document.getElementById("password").value
		if(link == ""){
			alert("链接不能为空!")
			exit()
		}
		document.getElementById("message").innerHTML = "请稍后..."
		document.getElementById("redBtn").style = "display:none;"
		document.getElementById("copyBtn").style = "display:none;"
		var xhr = new XMLHttpRequest();
		xhr.onreadystatechange = function(){
		if (xhr.readyState === 4){
			if (xhr.status === 200){
				downloadLink = xhr.responseText
				if(downloadLink.search("http") != -1){
				    document.getElementById("result").value = xhr.responseText
				    document.getElementById("redBtn").style = ""
				    document.getElementById("copyBtn").style = ""
				    document.getElementById("message").innerHTML = "解析完毕!"
				    document.getElementById("morefilebox").innerHTML = ""
				    setTimeout(function(){
                            document.getElementById("message").innerHTML = "欢迎使用"
                        }, 1500)
				}else{
				    if(downloadLink.search(",") != -1){
				        //多链接
				        document.getElementById('morefilebox').innerHTML = "";
				        result = downloadLink
				        array = result.split(';')
                        id = []
                        name = []
                        var para = document.createElement("p")
                        para.innerText = '单击选择文件下载'
                        morefilebox.appendChild(para)
                            for(i =0;i<array.length;i++){
                                var button = document.createElement("button")
                                button.setAttribute("onclick","jiexi2('"+array[i].split(',')[0]+"');")
                                button.setAttribute("class","btn btn-success btn-wd")
                                button.innerText = array[i].split(',')[1] + "\n"
                                morefilebox.appendChild(button)
                            }
				    }
				    else {
				        document.getElementById("message").innerHTML = "解析错误"
                        setTimeout(function(){
                            document.getElementById("message").innerHTML = "欢迎使用"
                        }, 1500)
				    }
				}
				
			console.error(xhr.statusText);
			}
		}
		};
		xhr.onerror = function (e) {
		console.error(xhr.statusText);
		};
		xhr.open('GET', './1.php?link=' + link + "&pwd=" + password + "&red=", true);
		xhr.send(null);
	}
	function red(){
	    location.href=downloadLink;
	}
	function copy(){
	    var link = document.getElementById("link").value
		var password = document.getElementById("password").value
        var textarea = document.createElement('textarea');
        document.body.appendChild(textarea);
        textarea.style.position = 'absolute';
        textarea.style.clip = 'rect(0 0 0 0)';
        textarea.value = 'http://wgame.miaovps.com:32022/1.php?link='+ link + "&pwd=" + password + "&red=114514";
        textarea.select();
        document.execCommand('copy', true);
        document.getElementById("message").innerHTML = "复制成功!"
        setTimeout(function(){
                    document.getElementById("message").innerHTML = "欢迎使用"
                }, 1500)
	}
	</script>
<div class="container py-2">
    <div class="row">
        <div class="col-md-12">
			<div class="logo">
				<a href="#">
					<h1>LanZou Cloud</h1>
				</a>
			</div>
            <div class="row">
                <div class="col-md-6 login-form mx-auto">
                    <!-- form card login -->
                    <div class="card">
                        <div class="card-header">
                            <h3 class="mb-0" id="message"></h3>
                        </div>
                        <div class="card-body">
							<div class="form-group">
								<input class="form-control" id="link" name="link" placeholder="分享链接" type="text" required="">
								<input class="form-control" id="password" name="password" placeholder="密码(可以为空)" type="text" required="">
								<input class="form-control" id="result" name="result" placeholder="解析结果" type="text" required="">
							</div>
							<div class="row mb-3">
							    <div class="col-lg-12 text-right"><button onclick="red();" style="display:none;"class="btn btn-success btn-wd " id="redBtn"><span>点击下载</span></button></div>
							    <div class="col-lg-12 text-right"><button onclick="copy();" style="display:none;"class="btn btn-success btn-wd " id="copyBtn"><span>点击复制跳转链接</span></button></div>
								<div class="col-lg-12 text-right"><button onclick="jiexi();" class="btn btn-success btn-wd " id="btnLogin"><span>点击解析</span></button></div>
							</div>
                        </div>
                        <!--/card-block-->
						<!---->
						<div class="card-footer">
							<div class="copy-text">Created with <i class="fa fa-heart"></i> by Hurry <a href="https://www.github.com/HurryBy/lanzou-directlink">项目地址</a></div>
							<div id="morefilebox">
							    
							    </div>
							    <div class="msg_desc">
                                    <a href="https://we.miaovps.com" ><img style="max-wIDth:100%;overflow:hidden;"  src="https://we.miaovps.com/static/images/f1.png" width="500" height="300"></a>
                                </div>
							
						</div>
                    </div>
                    <!-- /form card login -->
                </div>
            </div>
            <!--/row-->
        </div>
        <!--/col-->
    </div>
    <!--/row-->
</div>
<!--/container-->

<!-- jquery latest version -->
<script src="js/jquery.min.js"></script>
<!-- popper.min.js -->
<script src="js/popper.min.js"></script>    
<!-- bootstrap js -->
<script src="js/bootstrap.min.js"></script>
<!-- Jquery Rippler js -->
<script src="js/jquery.rippler.min.js"></script>	
<!-- script js -->
<script src="js/script.js"></script>
</body>
</html>